Ensure a message is printed on test failure
authorAlex Crichton <alex@alexcrichton.com>
Wed, 23 Jul 2014 19:49:32 +0000 (12:49 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Wed, 23 Jul 2014 20:08:57 +0000 (13:08 -0700)
This previously relied on the test itself printing failure, but this is not
always the case for test which, for example, segfault. Instead this ensures that
*something* is always printed when a test fails, normally a short blurb about
what executable failed to run.

src/bin/cargo-test.rs
tests/test_cargo_test.rs

index 707681ae6831c3a9fa11d63d00eb9573b13e393d..1337b57b87a6f83b97273e1f6b5c5252a1029f8b 100644 (file)
@@ -9,12 +9,13 @@ extern crate serialize;
 extern crate hammer;
 
 use std::os;
+use std::io::process::ExitStatus;
 
 use cargo::ops;
 use cargo::{execute_main_without_stdin};
 use cargo::core::{MultiShell};
 use cargo::util;
-use cargo::util::{CliResult, CliError, human};
+use cargo::util::{CliResult, CliError, CargoError};
 use cargo::util::important_paths::find_project_manifest;
 
 #[deriving(PartialEq,Clone,Decodable)]
@@ -62,7 +63,13 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
     for file in test_executables.iter() {
         try!(util::process(test_dir.join(file.as_slice()))
                   .args(options.rest.as_slice())
-                  .exec().map_err(|_| CliError::from_boxed(human(""), 1)));
+                  .exec().map_err(|e| {
+            let exit_status = match e.exit {
+                Some(ExitStatus(i)) => i as uint,
+                _ => 1,
+            };
+            CliError::from_boxed(e.mark_human(), exit_status)
+        }));
     }
 
     Ok(None)
index 1a0ff9c942cc889e4713919faf1a450250c63937..d32da323e4c5d5e62c4c88d0b33d54c90e9cdff3 100644 (file)
@@ -106,7 +106,12 @@ test!(cargo_test_failing_test {
                                     test result: FAILED. 0 passed; 1 failed; \
                                     0 ignored; 0 measured\n\n",
                                     COMPILING, p.root().display(),
-                                    sep = path::SEP)));
+                                    sep = path::SEP))
+              .with_stderr(format!("\
+task '<main>' failed at 'Some tests failed', [..]
+Could not execute process `{test}[..]` (status=101)
+", test = p.root().join("target/test/foo").display()))
+              .with_status(101));
 })
 
 test!(test_with_lib_dep {